﻿@model InspectionPlanModel
@using Nop.Web.Framework.Localization

@Html.ValidationSummary(true)
@Html.HiddenFor(model => model.Id)

<div class="content">
    <div class="form-horizontal">
        <div id="category-edit" class="nav-tabs-custom">
            <ul class="nav nav-tabs">
                @Html.RenderBootstrapTabHeader("tab-info", new LocalizedString("基本信息"), true)
            </ul>
            <div class="tab-content">
                @Html.RenderBootstrapTabContent("tab-info", @TabInfo(), true)
            </div>
        </div>
    </div>
</div>

@{
    //custom tabs
    var eventMessage = new AdminTabStripCreated(this.Html, "category-edit");
    EngineContext.Current.Resolve<IEventPublisher>().Publish(eventMessage);
    foreach (var eventBlock in eventMessage.BlocksToRender)
    {
        @eventBlock
    }
}

@*save selected tab name*@
<input type="hidden" id="selected-tab-name" name="selected-tab-name" value="@(Html.GetSelectedTabName())">

@helper TabInfo()
{
    <div class="content" style="padding-bottom:0;">
        <div class="form-horizontal">
            <div class="panel-group">
                <div class="panel panel-default">
                    <div class="panel-body">
                        @if (Model.Id > 0)
                        {
                            <div class="form-group">
                                <div class="col-md-3">
                                    @Html.NopLabelFor(model => model.PNo)
                                </div>
                                <div class="col-md-9">
                                    @Html.NopDisplayFor(model => model.PNo)
                                </div>
                            </div>
                        }
                        <div class="form-group">
                            <div class="col-md-3">
                                @Html.NopLabelFor(model => model.Name)
                            </div>
                            <div class="col-md-9">
                                @Html.NopEditorFor(model => model.Name)
                                @Html.ValidationMessageFor(model => model.Name)
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-md-3">
                                @Html.NopLabelFor(model => model.TypeId)
                            </div>
                            <div class="col-md-9">
                                @Html.NopDropDownListFor(model => model.TypeId, Model.AvailableTypes)
                                @Html.ValidationMessageFor(model => model.TypeId)
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-md-3">
                                @Html.NopLabelFor(model => model.AimId)
                            </div>
                            <div class="col-md-9">
                                @Html.NopDropDownListFor(model => model.AimId, Model.AvailableAims)
                                @Html.ValidationMessageFor(model => model.AimId)
                            </div>
                        </div>
                        <div class="form-group" id="pnlCategoryIds">
                            <div class="col-md-3">
                                @Html.NopLabelFor(model => model.CategoryIds)
                            </div>
                            <div class="col-md-9">
                                @Html.EditorFor(model => model.CategoryIds, new { SelectList = Model.AvailableCategorys })
                                @Html.ValidationMessageFor(model => model.CategoryIds)
                                <script>
                                    $(document).ready(function() {
                                        var customerRolesIdsInput = $('#@Html.FieldIdFor(model => model.CategoryIds)').data("kendoMultiSelect");
                                        customerRolesIdsInput.setOptions({
                                            customerRolesIdsInput: false
                                        });
                                        @if (Model.AvailableCategorys.Count == 0)
                                        {
                                            <text>
                                                customerRolesIdsInput.setOptions({
                                                    enable: false,
                                                    placeholder: '未找到设备分类'
                                                });
                                                customerRolesIdsInput._placeholder();
                                                customerRolesIdsInput._enable();
                                            </text>
                                        }
                                    });
                                </script>
                            </div>
                        </div>
                        <div class="form-group" id="pnlPlaceIds">
                            <div class="col-md-3">
                                @Html.NopLabelFor(model => model.PlaceIds)
                            </div>
                            <div class="col-md-9">
                                @Html.EditorFor(model => model.PlaceIds, new { SelectList = Model.AvailablePlaces })
                                @Html.ValidationMessageFor(model => model.PlaceIds)
                                <script>
                                    $(document).ready(function() {
                                        var placeIdsInput = $('#@Html.FieldIdFor(model => model.PlaceIds)').data("kendoMultiSelect");
                                        placeIdsInput.setOptions({
                                            placeIdsInput: false
                                        });
                                        @if (Model.AvailablePlaces.Count == 0)
                                        {
                                            <text>
                                                placeIdsInput.setOptions({
                                                    enable: false,
                                                    placeholder: '未找到巡检点'
                                                });
                                                placeIdsInput._placeholder();
                                                placeIdsInput._enable();
                                            </text>
                                        }
                                    });
                                </script>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-md-3">
                                @Html.NopLabelFor(model => model.TeamId)
                            </div>
                            <div class="col-md-9">
                                @Html.EditorFor(model => model.TeamId, new { SelectList = Model.AvailableDepartments })
                                @Html.ValidationMessageFor(model => model.TeamId)
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-md-3">
                                @Html.NopLabelFor(model => model.PersonId)
                            </div>
                            <div class="col-md-9">
                                @Html.NopDropDownListFor(model => model.PersonId, Model.AvailableUsers)
                                @Html.ValidationMessageFor(model => model.PersonId)
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-md-3">
                                @Html.NopLabelFor(model => model.MaintenanceTeamId)
                            </div>
                            <div class="col-md-9">
                                @Html.EditorFor(model => model.MaintenanceTeamId, new { SelectList = Model.AvailableMaintenanceDepartments })
                                @Html.ValidationMessageFor(model => model.MaintenanceTeamId)
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-md-3">
                                @Html.NopLabelFor(model => model.MaintenancePersonId)
                            </div>
                            <div class="col-md-9">
                                @Html.NopDropDownListFor(model => model.MaintenancePersonId, Model.AvailableMaintenanceUsers)
                                @Html.ValidationMessageFor(model => model.MaintenancePersonId)
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-md-3">
                                @Html.NopLabelFor(model => model.StartOn)
                            </div>
                            <div class="col-md-9">
                                @Html.NopEditorFor(model => model.StartOn)
                                @Html.ValidationMessageFor(model => model.StartOn)
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-md-3">
                                @Html.NopLabelFor(model => model.EndOn)
                            </div>
                            <div class="col-md-9">
                                @Html.NopEditorFor(model => model.EndOn)
                                @Html.ValidationMessageFor(model => model.EndOn)
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-md-3">
                                @Html.NopLabelFor(model => model.Published)
                            </div>
                            <div class="col-md-9">
                                @Html.NopEditorFor(x => x.Published)
                                @Html.ValidationMessageFor(model => model.Published)
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        $(document).ready(function () {
        $("#@Html.FieldIdFor(model => model.TeamId)").change(function () {
            var selectedItem = $(this).val();
            var ddlStates = $("#@Html.FieldIdFor(model => model.PersonId)");
            $.ajax({
                cache: false,
                type: "GET",
                url: "@(Url.Action("GetUsersByDepartmentId", "Customer"))",
                data: { "departId": selectedItem },
                success: function(data) {
                    ddlStates.html('');
                    $.each(data, function(id, option) {
                        ddlStates.append($('<option></option>').val(option.id).html(option.name));
                    });
                },
                error: function(xhr, ajaxOptions, thrownError) {
                    alert('Failed to retrieve states.');
                }
            });
        });
        $("#@Html.FieldIdFor(model => model.MaintenanceTeamId)").change(function () {
            var selectedItem = $(this).val();
            var ddlStates = $("#@Html.FieldIdFor(model => model.MaintenancePersonId)");
            $.ajax({
                cache: false,
                type: "GET",
                url: "@(Url.Action("GetUsersByDepartmentId", "Customer"))",
                data: { "departId": selectedItem },
                success: function(data) {
                    ddlStates.html('');
                    $.each(data, function(id, option) {
                        ddlStates.append($('<option></option>').val(option.id).html(option.name));
                    });
                },
                error: function(xhr, ajaxOptions, thrownError) {
                    alert('Failed to retrieve states.');
                }
            });
        });
        $("#@Html.FieldIdFor(model => model.AimId)").change(toggleAim);
        toggleAim();
        });
        function toggleAim() {
            var aim = $('#@Html.FieldIdFor(model => model.AimId)').val() * 1;
            switch (aim) {
                case @((int)Nop.Core.Domain.XJ.AimTypeEnum.巡检点):
                    $("#pnlPlaceIds").show();
                    $("#pnlCategoryIds").hide();
                    break;
                case @((int)Nop.Core.Domain.XJ.AimTypeEnum.设备分类):
                    $("#pnlPlaceIds").hide();
                    $("#pnlCategoryIds").show();
                    break;
                default:
                    break;
            }
        }
    </script>
}
